<html>
<body>

	<table align=center width=50% border=1>

    	<form method=post>
<?php

include "kernel.php";
include "adw_functions.php";

if ($_POST[dopost]) {

	foreach ($_POST[rebase] as $key=>$value) {

	    $r = mysql_query("select * from postponed where id='$key'");

    	$q = mysql_fetch_assoc($r);
	    mysql_query($q[query]);
	    mysql_query("update postponed set isupdated='1', execdate='".date("Y.m.d H:i:s")."' where id='".$q[id]."'");

    }

	echo "REBASED.";
}


$r = mysql_query("select * from postponed where isupdated=0 order by id");

while($q = mysql_fetch_assoc($r)) {

	$query = $q['query'];

    ereg(" id='([0-9]+)'",$query,$args);

    $squadid = $args[0];
    $squadid = ereg_replace("'","",$squadid);
    $squadid = ereg_replace(" id=","",$squadid);

    ereg("id='([0-9]+)'",$query,$args);

    $fieldid = $args[0];
    $fieldid = ereg_replace("'","",$fieldid);
    $fieldid = ereg_replace("id=","",$fieldid);


	//echo "squad: $squadid, field: $fieldid";

    $squad = GetSquadById($squadid);
    $field = GetBaseById($fieldid);

    echo "<tr>
    		<td>$squad[tag]</td>
            <td>$field[name]</td>
            <td><input type=checkbox name=rebase[$q[id]]</td>
         </tr>";


}

    echo "<tr>
    		<td colspan=3 align=center><input type=submit name=dopost value='REBASE'></td>
         </tr>";


?>
	</table>
</body>
</html>